

//
//  YDChoosePayViewController.m
//  PeiZiWangBei
//
//  Created by 巨彦新 on 2018/1/18.
//  Copyright © 2018年 LK-IOS. All rights reserved.
//

#import "YDChoosePayViewController.h"
#import "YDChoosePayTypeCell.h"

#import "YDOneRechargeViewController.h"
#import "YDAliPayViewController.h"
#import "YDRechargeController.h"

@interface YDChoosePayViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong)UITableView *tableView;


/**
 tableview的头视图
 */
@property (nonatomic, strong)UIView *headview;

/**
 支付方式数据源
 */
@property (nonatomic, strong)NSMutableArray *dataList;


@end

@implementation YDChoosePayViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"账户充值";
    [self tableView];
    
}



#pragma mark - UITbaleviewDelegate && UITableviewDatasource

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataList.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YDChoosePayTypeCell *cell = [YDChoosePayTypeCell cellWithTableView:tableView];
    cell.selectedIcon.hidden = YES;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.payDic = [self.dataList objectAtIndex:indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    switch (indexPath.row) {
//        case 0:{
//            YDAliPayViewController *vc = [[YDAliPayViewController alloc] init];
//            [self.navigationController pushViewController:vc animated:YES];
//        }
//
//            break;
//        case 1:{//银联充值
//            YDOneRechargeViewController *vc = [[YDOneRechargeViewController alloc] init];
//            vc.payType = SYPayType_card;
//            //            YDRechargeController *vc = [[YDRechargeController alloc] init];
//            [self.navigationController pushViewController:vc animated:YES];
//        }
//            break;
//        case 2:{
//            YDOneRechargeViewController *vc = [[YDOneRechargeViewController alloc] init];
//            vc.payType = SYPayType_qq;
//            [self.navigationController pushViewController:vc animated:YES];
//
//        }
//            break;
//        case 3:{
//            YDOneRechargeViewController *vc = [[YDOneRechargeViewController alloc] init];
//            vc.payType = SYPayType_jd;
//            [self.navigationController pushViewController:vc animated:YES];
//        }
//            break;
//        default:
//            break;
//    }
    
    YDOneRechargeViewController *vc = [[YDOneRechargeViewController alloc] init];
    vc.payType = SYPayType_card;
    //            YDRechargeController *vc = [[YDRechargeController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

//tableView
-(UITableView *)tableView
{
    if (_tableView == nil) {
        
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        [self.view addSubview:tableView];
        tableView.backgroundColor = [UIColor colorWithHexString:mainGray];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.estimatedRowHeight = 0;
        tableView.estimatedSectionFooterHeight = 0;
        tableView.estimatedSectionHeaderHeight = 0;
        tableView.tableHeaderView = self.headview;
        tableView.rowHeight = isPhoneX ?rateX812(40) : rate750(40);
        [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.equalTo(self.view);
        
            
        }];
        if (isIos11) {
            tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        _tableView = tableView;
    }
    return _tableView;
}

-(UIView *)headview
{
    if (_headview == nil) {
        _headview = [UIView new];
        UILabel *lbl = [UILabel new];
        lbl.textColor = [UIColor colorWithHexString:battleshipGrey];
        [_headview addSubview:lbl];
        lbl.text = @"选择充值方式";
        lbl.font = [UIFont systemFontOfSize:14];
        _headview.backgroundColor = [UIColor colorWithHexString:mainGray];
        _headview.frame = CGRectMake(0, 0, LKScreenW, isPhoneX ? rateX812(55) : rate750(55));
        [lbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(rate375(20)));
            make.centerY.equalTo(_headview);
        }];
    }
    return _headview;
}

- (NSMutableArray *)dataList
{
    if (!_dataList) {
        _dataList = [NSMutableArray arrayWithCapacity:2];
//        NSMutableDictionary *dic1 = [NSMutableDictionary dictionaryWithDictionary:@{@"title" : @"支付宝",
//                                                                                    @"isSelected" : @0}];
//        NSMutableDictionary *dic2 = [NSMutableDictionary dictionaryWithDictionary:@{@"title" : @"银行卡",
//                                                                                    @"isSelected" : @0}];
//        NSMutableDictionary *dic3 = [NSMutableDictionary dictionaryWithDictionary:@{@"title" : @"qq",
//                                                                                    @"isSelected" : @0}];
//        NSMutableDictionary *dic4 = [NSMutableDictionary dictionaryWithDictionary:@{@"title" : @"京东",
//                                                                                    @"isSelected" : @0}];
//
//
//
//        [_dataList addObject:dic1];
//        [_dataList addObject:dic2];
//        [_dataList addObject:dic3];
//        [_dataList addObject:dic4];

        NSMutableDictionary *dic2 = [NSMutableDictionary dictionaryWithDictionary:@{@"title" : @"银行卡",
                                                                                    @"isSelected" : @0}];

        
        [_dataList addObject:dic2];

        
    }
    return _dataList;
}
@end
